var token = $.cookie("m-token");
axios.defaults.headers.common['Authorization'] = "Bearer " + token;
axios.defaults.timeout = 3000;

/**
 * 请求拦截器
 */
axios.interceptors.request.use(function (config) {
    // 在发送请求之前做些什么
    var c = config;
    c.method = 'post';
    //这里覆盖了原来的处理  如出现数据问题来这里解决
    c.transformRequest = [function (data) {
        // return Qs.stringify(data); 需要引入qs
        if (!data) {
            return null
        }

        var par = jQuery.param(data);
        var search = new URLSearchParams(par);
        return search;
    }];
    return c;
}, function (error) {
    // 对请求错误做些什么
    return Promise.reject(error);
});


/**
 * 响应拦截器
 */
axios.interceptors.response.use(function (response) {
    // 对响应数据做点什么
    return response.data;
}, function (error) {
    // 对响应错误做点什么
    return Promise.reject(error);
});


Vue.prototype.dateTime = function (time) {
    if (!time) return "";

    function fullZero(minute) {
        return minute < 10 ? "0" + minute : minute;
    }

    var now = new Date(parseInt(time));
    var year = now.getFullYear().toString().substring(2);
    var month = now.getMonth() + 1;
    var date = now.getDate();
    var hour = now.getHours();
    var minute = now.getMinutes();
    return year + "-" + fullZero(month) + "-" + fullZero(date) + " " + fullZero(hour) + ":" + fullZero(minute);
};

function log(d) {
    var data = {};
    $.each(d, function (index, item) {
        if (typeof(item) != "function") {
            data[index] = item;
        }
    });
    console.log(data);
};


function search(key) {
    var search = new URLSearchParams(window.location.search.substr(1));
    return search.get(key);
};









